//
//  YMFavView.swift
//  YMSwiftUI
//
//  Created by anscen on 2022/4/20.
//

import SwiftUI

struct YMFavView: View {
    @State var listData :[YMBook] = []
    @State var listAdap :[GridItem] = [GridItem(.adaptive(minimum: list_width, maximum: list_height), spacing: 0, alignment: .center)]
    @State var state    :YMHomeCaseState = .list
    var body: some View {
        GeometryReader.init { rootSize in
            VStack {
                List {
                    ForEach(listData, id: \.self){
                        item in
                        if self.state == .grid{
                            YMBookCaseCell(book: item)
                        }else{
                            YMListCell(book: item,width: rootSize.size.width)
                        }
                    }.onDelete { sets in
                        if let row = sets.first{
                            let item = self.listData[row]
                            shelfQueue.deleteData(bookId: item.bookId ?? "") { success in
                                self.listData.remove(at: row)
                            }
                        }
                    }
                }.listStyle(.plain).navigationBarBackButtonHidden(true).navigationBarItems(leading: BaseNavigationBarBackButton()).navigationBarTitle("我的收藏")
            }.onAppear {
                loadData()
            }
        }
    }
    func loadData(){
        shelfQueue.getData { datas in
            self.listData = datas
        }
    }
}
